// JavaScript Document
// JavaScript Document
//require MyClass.js
//require MyLibraryManager.js
//Clase utilizada para cargar en forma dinamica y a demanda todos los includes JS y CSS necesarios para todas las secciones del mapa

// SINGLETON!!!
DinamicIncludes_Map = new MyClass({
	CLASS_NAME: "DinamicIncludes_Map",
	//flags para saber si ya estan cargadas las secciones.
	_includePreload: false,
	_includeGeneral: false,
	_includeHistorico: false,
	_includeMisPuntos: false,
	_includeMisZonas: false,
	_includeLogistica: false,
	_includeTablero: false,
	_includeGestorDir: false,
	_includeFijos: false,
	_includeMisRutas: false,

	//LIBS
	_libsPreload: new Array(
					//'openlayers/lib/OpenLayers.js',
					'js/browserdetect.js',
					//'js/json.js',
					//'js/jquery/jquery-1.4.2.min.js',
					//'js/jshashtable.js'	,
					'js/MapIcons.js'
					),
	_libsGeneral: new Array(
					'styles/gmap.css',
    				'styles/minimenu.css',

    				'js/clases/cGeoController.js',
    				'js/clases/cHistorico.js',
    				'js/clases/MyOLServerMap.js',
    				'js/clases/cMapa.js',
    				'js/clases/cMapController.js',

    				'js/gmap.js',
					'js/minimenu.js',
					'js/accordionMenu/SpryAccordion.js',
					'js/accordionMenu/SpryAccordion.css',
					'js/validator.js',
					'js/dhtmlwindow/windowfiles/dhtmlwindow.css',
					'js/dhtmlwindow/modalfiles/modal.css',
					'js/dhtmlwindow/windowfiles/dhtmlwindow.js',
					'js/dhtmlwindow/modalfiles/modal.js',
					'js/popupmenu.js',
					'js/dtree/dtree.css',
					'js/dtree/dtree.js',
					'js/clases/RecorridoHistorico.js',
    				'js/clases/SortArray.js',
				    'js/clases/MyDate.js',
    				'js/myClass/MyAjax.js',
				    'js/myClass/MySortArray.js',
				    'js/myClass/MyUtils.js',
				    'js/myClass/MyValidator.js',
					'js/myClass/MyBoundingHandler.js',
					'js/miniMenu/miniMenu.css',
					'js/miniMenu/MiniMenu.js',
    				'js/tabMenu/styles/basictab.css',
					'js/tabMenu/TabMenu.js',
    				'js/complementos/contactos/ContactosLIB.css',
					'js/complementos/contactos/ContactosLIB.js',
					'js/componentes/SelectSwitcher.js',
				    'js/componentes/MonitorContainer.css',
				    'js/componentes/MonitorButton.js',
				    'js/componentes/MonitorContainer.js',
					'js/componentes/FloatingDisplay.css',
				    'js/componentes/FloatingDisplay.js',
				    'js/componentes/ToolMeasure.js',
				    'js/componentes/ToolArea.js',
				    'js/componentes/TableroContainer.css',
				    'js/componentes/TableroContainer.js',
					'js/clases/GestorDirCercanos.js',
					'js/jscolor/jscolor.js',
					'js/MMapPanels/fijos.js',
    				'js/MMapPanels/vehiculos2.js',
        			'js/MMapPanels/seguimiento.js',
					'js/MMapPanels/mispuntos.js',
					'js/MMapPanels/miszonas.js',
					'js/MMapPanels/misrutas.js',
					'js/MMapPanels/miscelaneas.js'
					),
	_libsTablero: new Array(
					'js/tablero/tablero.js',
					'js/tablero/Velocimetro.js',
					'js/tablero/Rpm.js',
					'js/tablero/Brujula.js',
					'js/tablero/Odometro.js',
					'js/tablero/LedMarquee.js',
					'js/tablero/Voltimetro.js',
					'js/tablero/Fuelandtemp.js',
					'js/tablero/IndicadorPuertas.js',
					'js/tablero/IndicadorGeneral.js'
					),

	//general properties
	_loadingPanel: null,

	init: function(){
	},

	_getLoadingPanel: function(){
		this._loadingPanel = document.getElementById('mapLoadingPanel');
		var large = this._libsPreload.length + this._libsGeneral.length;
		large += this._libsTablero.length;
		_loadingBar.reset(large);
	},

	_beforeIncludeLib: function(library){
		_loadingBar.setText('loading '+library);
	},

	_afterIncludeLib: function(library){
		_loadingBar.progress();
	},

	setMessage: function(msg){
		_loadingBar.setText(msg);
	},
	//************************************ INCLUDE PRELOAD *********************************//
	includePreload: function(){
		if (!this._includePreload){
			var me = this;
			if (this._loadingPanel==null)
				this._getLoadingPanel();

			this._loadingPanel.style.display = "block";
			myLibraryManager.beforeChargeLib = function(str){me._beforeIncludeLib(str);};
			myLibraryManager.afterChargeLib = function(str){me._afterIncludeLib(str);};

			var F = function(){
								initializeGlobalVars();
								me._includePreload = true;
								me.includeGeneral();
							  };

			myLibraryManager.charge(this._libsPreload, F);
		}
	},

	isPreloadInclude: function(){
		return this._includePreload;
	},

	//************************************ INCLUDE GENERAL *********************************//
	includeGeneral: function(){
		if (!this._includeGeneral){
			var me = this;
			if (this._loadingPanel==null)
				this._getLoadingPanel();

			this._loadingPanel.style.display = "block";
			var F = function(){
								me._includeMisPuntos = true;
								me._includeMisZonas = true;
								me._includeGeneral = true;
								me.includeTablero();
							  };
			myLibraryManager.charge(this._libsGeneral, F);
		}
	},

	isGeneralInclude: function(){
		return this._includeGeneral;
	},

	//************************************ INCLUDE HISTORICO *********************************//
	includeHistorico: function(){
		if (!this._includeHistorico){
			if (this._loadingPanel==null)
				this._getLoadingPanel();
			var X = new Array(
					'js/jscolor/jscolor.js',
					'js/MMapPanels/historico2.js'
//					'js/calendar/skins/aqua/theme.css',
//					'js/calendar/calendar.js',
//					'js/calendar/lang/calendar_es.js',
//					'js/calendar/calendar_setup.js'
					);
			_loadingBar.reset(X.length);
			var loadingPanel = this._loadingPanel;
			var me = this;
			var F = function(){ CargarHistorico();
								loadingPanel.style.display = "none";
								me._includeHistorico = true;
							  };
			loadingPanel.style.display = "block";
			myLibraryManager.charge(X,F);
		}
	},

	isHistoricoInclude: function(){
		return this._includeHistorico;
	},

	//************************************ INCLUDE MIS PUNTOS *********************************//
	includeMisPuntos: function(){
		if (!this._includeMisPuntos){
			if (this._loadingPanel==null)
				this._getLoadingPanel();
			var X = new Array(
					'js/MMapPanels/mispuntos.js'
					);
			_loadingBar.reset(X.length);
			var me = this;
			var loadingPanel = this._loadingPanel;
			var F = function(){ CargarMisGrupos();
								loadingPanel.style.display = "none";
								me._includeMisPuntos = true;
							  };
			this._loadingPanel.style.display = "block";
			myLibraryManager.charge(X,F);

		}
	},

	isMisPuntosInclude: function(){
		return this._includeMisPuntos;
	},

	//************************************ INCLUDE MIS ZONAS *********************************//
	includeMisZonas: function(){
		if (!this._includeMisZonas){
			if (this._loadingPanel==null)
				this._getLoadingPanel();
			var X = new Array(
					'js/jscolor/jscolor.js',
					'js/MMapPanels/miszonas.js'
					);
			_loadingBar.reset(X.length);
			var loadingPanel = this._loadingPanel;
			var me = this;
			var F = function(){ CargarMisZonas();
								loadingPanel.style.display = "none";
								me._includeMisZonas = true;
							  };
			this._loadingPanel.style.display = "block";
			myLibraryManager.charge(X,F);

		}
	},

	isMisZonasInclude: function(){
		return this._includeMisZonas;
	},

	//************************************ INCLUDE LOGISTICA *********************************//
	includeLogistica: function(){
		if (!this._includeMisZonas){
			this.includeMisZonas();
		}
		if (!this._includeLogistica){
			if (this._loadingPanel==null)
				this._getLoadingPanel();
			var X = new Array(
					'js/MMapPanels/reglas.js'
					);
			_loadingBar.reset(X.length);
			var me = this;
			var loadingPanel = this._loadingPanel;
			var F = function(){ CargarReglas();
								loadingPanel.style.display = "none";
								me._includeLogistica = true;
							  };
			this._loadingPanel.style.display = "block";
			myLibraryManager.charge(X,F);

		}
	},

	isLogisticaInclude: function(){
		return this._includeLogistica;
	},

	//************************************ INCLUDE TABLERO *********************************//
	includeTablero: function(){
		if (!this._includeTablero){
			if (this._loadingPanel==null)
				this._getLoadingPanel();

			var loadingPanel = this._loadingPanel;
			var me = this;
			var F = function(){
								//initialize();
								inicializarCantMapas();
								initializeTablero();
								me._includeTablero = true;
								document.getElementById('gMapContainer').style.visibility = "visible";
							  };
			this._loadingPanel.style.display = "block";
			myLibraryManager.charge(this._libsTablero,F);
		}
	},

	isTableroInclude: function(){
		return this._includeTablero;
	},

	//************************************ INCLUDE MISCELANEAS GESTORDIR *********************************//
	includeGestorDir: function(){
		if (!this._includeGestorDir){
			if (this._loadingPanel==null)
				this._getLoadingPanel();
			var X = new Array(
					'js/clases/GestorDirElement.js',
					'js/MMapPanels/gestordir.js'
					);
			_loadingBar.reset(X.length);
			var loadingPanel = this._loadingPanel;
			var me = this;
			var F = function(){ CargarGestorDir();
								loadingPanel.style.display = "none";
								me._includeGestorDir = true;
							  };
			loadingPanel.style.display = "block";
			myLibraryManager.charge(X,F);
		}
	},

	isGestorDirInclude: function(){
		return (this._includeGestorDir);
	},
	//************************************ INCLUDE FIJOS *********************************//
	includeFijos: function(){
		if (!this._includeFijos){
			if (this._loadingPanel==null)
				this._getLoadingPanel();
			var X = new Array(
					'js/MMapPanels/fijos.js'
			);
			_loadingBar.reset(X.length);
			var loadingPanel = this._loadingPanel;
			var me = this;
			var F = function(){
					CargarMisFijos();
					loadingPanel.style.display = "none";
					me._includeGestorDir = true;
			};
			loadingPanel.style.display = "block";
			myLibraryManager.charge(X,F);
		}
	},

	isFijosInclude: function(){
		return (this._includeFijos);
	},
	//************************************ INCLUDE MIS RUTAS *********************************//
	includeMisRutas: function(){
		if (!this._includeMisRutas){
			if (this._loadingPanel==null)
				this._getLoadingPanel();
			var X = new Array(
					'js/MMapPanels/misrutas.js'
					);
			_loadingBar.reset(X.length);
			var loadingPanel = this._loadingPanel;
			var me = this;
			var F = function(){ cMapController.cargarMisRutas();
								loadingPanel.style.display = "none";
								me._includeMisRutas = true;
							  };
			this._loadingPanel.style.display = "block";
			myLibraryManager.charge(X,F);

		}
	},

	isMisRutasInclude: function(){
		return this._includeMisRutas;
	}
});

dinamicIncludes_Map = new DinamicIncludes_Map();